//
//  Extention + UIbarButtonItem.swift
//  XLWibo-Swift
//
//  Created by 王林 on 2016/11/12.
//  Copyright © 2016年 木木. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(title: String? , imgName :String? = " " , font: CGFloat ,  target: Any?, action: Selector?) {
        
        let button = UIButton()
        button.setTitle(title, for: .normal)
        
        if imgName != nil {
            button.setImage(UIImage(named: imgName!), for:.normal )
            button.setImage(UIImage(named: imgName! + "_highlighted"), for: .highlighted)
        }
       
        button.titleLabel?.font = UIFont.systemFont(ofSize: font)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        if (action != nil) {
                 button.addTarget(target, action: action!, for: .touchUpInside)
        }
   
        button.sizeToFit()
        
        self.init()
        self.customView = button
        
    }

}
